package com.yager.controller;

import com.yager.model.House;
import com.yager.service.AccuseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/accuse")
public class AccuseController {

    @Autowired
    private AccuseService accuseService;

    @RequestMapping("/addAccuse")
    public String addAccuse(@RequestParam("accuseimage") MultipartFile[] file, HttpServletRequest req,HttpSession session){
        System.out.println("好耶 举报请求发送成功");
        String accuseType=req.getParameter("accusetype");
        String accuseDescription = req.getParameter("accusedescription");
        String userid=req.getParameter("userid");
        String beAccusedId=(String) session.getAttribute("beAccusedId");

        accuseService.addNewAccuse(file,accuseType,accuseDescription,userid,beAccusedId);

        session.removeAttribute("beAccusedId");

        return "user/userInfo";
    }

    @RequestMapping("/toAddFromHouse")
    public String toAddFromHouse(HttpSession session){
        House house=(House) session.getAttribute("Onehouse");
        String id=house.getHouseid();
        session.setAttribute("beAccusedId",id);
        return "accuse/addAccuse";
    }

    @RequestMapping("/toAddFromUser")
    public String toAddFromUser(){
        return null;
    }

}
